import 'package:my_blog_flutter/generated/json/base/json_convert_content.dart';
import 'package:my_blog_flutter/app/modules/home/models/home_entity.dart';

HomeEntity $HomeEntityFromJson(Map<String, dynamic> json) {
  final HomeEntity homeEntity = HomeEntity();
  final int? code = jsonConvert.convert<int>(json['code']);
  if (code != null) {
    homeEntity.code = code;
  }
  final String? message = jsonConvert.convert<String>(json['message']);
  if (message != null) {
    homeEntity.message = message;
  }
  final HomeData? data = jsonConvert.convert<HomeData>(json['data']);
  if (data != null) {
    homeEntity.data = data;
  }
  final int? timestamp = jsonConvert.convert<int>(json['timestamp']);
  if (timestamp != null) {
    homeEntity.timestamp = timestamp;
  }
  return homeEntity;
}

Map<String, dynamic> $HomeEntityToJson(HomeEntity entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['code'] = entity.code;
  data['message'] = entity.message;
  data['data'] = entity.data?.toJson();
  data['timestamp'] = entity.timestamp;
  return data;
}

extension HomeEntityExtension on HomeEntity {
  HomeEntity copyWith({
    int? code,
    String? message,
    HomeData? data,
    int? timestamp,
  }) {
    return HomeEntity()
      ..code = code ?? this.code
      ..message = message ?? this.message
      ..data = data ?? this.data
      ..timestamp = timestamp ?? this.timestamp;
  }
}

HomeData $HomeDataFromJson(Map<String, dynamic> json) {
  final HomeData homeData = HomeData();
  final int? totalCount = jsonConvert.convert<int>(json['totalCount']);
  if (totalCount != null) {
    homeData.totalCount = totalCount;
  }
  final List<HomeDataList>? list = (json['list'] as List<dynamic>?)?.map(
          (e) => jsonConvert.convert<HomeDataList>(e) as HomeDataList).toList();
  if (list != null) {
    homeData.list = list;
  }
  return homeData;
}

Map<String, dynamic> $HomeDataToJson(HomeData entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['totalCount'] = entity.totalCount;
  data['list'] = entity.list?.map((v) => v.toJson()).toList();
  return data;
}

extension HomeDataExtension on HomeData {
  HomeData copyWith({
    int? totalCount,
    List<HomeDataList>? list,
  }) {
    return HomeData()
      ..totalCount = totalCount ?? this.totalCount
      ..list = list ?? this.list;
  }
}

HomeDataList $HomeDataListFromJson(Map<String, dynamic> json) {
  final HomeDataList homeDataList = HomeDataList();
  final int? id = jsonConvert.convert<int>(json['id']);
  if (id != null) {
    homeDataList.id = id;
  }
  final String? title = jsonConvert.convert<String>(json['title']);
  if (title != null) {
    homeDataList.title = title;
  }
  final String? content = jsonConvert.convert<String>(json['content']);
  if (content != null) {
    homeDataList.content = content;
  }
  final String? createTime = jsonConvert.convert<String>(json['createTime']);
  if (createTime != null) {
    homeDataList.createTime = createTime;
  }
  final int? state = jsonConvert.convert<int>(json['state']);
  if (state != null) {
    homeDataList.state = state;
  }
  return homeDataList;
}

Map<String, dynamic> $HomeDataListToJson(HomeDataList entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['id'] = entity.id;
  data['title'] = entity.title;
  data['content'] = entity.content;
  data['createTime'] = entity.createTime;
  data['state'] = entity.state;
  return data;
}

extension HomeDataListExtension on HomeDataList {
  HomeDataList copyWith({
    int? id,
    String? title,
    String? content,
    String? createTime,
    int? state,
  }) {
    return HomeDataList()
      ..id = id ?? this.id
      ..title = title ?? this.title
      ..content = content ?? this.content
      ..createTime = createTime ?? this.createTime
      ..state = state ?? this.state;
  }
}